package com.aaa.service.impl;

import com.aaa.entity.Comment;
import com.aaa.entity.CommentPraise;
import com.aaa.mapper.CommentMapper;
import com.aaa.mapper.CommentPraiseMapper;
import com.aaa.service.ICommentPraiseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.javafx.collections.MappingChange;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Bean
 * @since 2021-09-07
 */
@Service
public class CommentPraiseServiceImpl extends ServiceImpl<CommentPraiseMapper, CommentPraise> implements ICommentPraiseService {
    @Autowired
    CommentPraiseMapper commentPraiseMapper;
    @Autowired
    CommentMapper commentMapper;
    @Autowired
    NettyPushServerImpl nettyPushServer;

    public boolean add(Integer cid,Integer uid){
        Comment comment = commentMapper.selectById(cid);
        Integer add = commentPraiseMapper.add(cid, uid,comment.getUid()==uid?null:0);
        if (add==1){
            if(comment.getUid()!=uid) {
                String uname = commentPraiseMapper.uname(uid);
                nettyPushServer.pushidServer(comment.getUid().toString(), "你的评论被" + uname + "赞了");
            }
            return true;
        }
        return false;
    }

}
